<template>
  <div class="app-container">
    <el-row>

      <el-col :span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">

            <el-col :span="1.5">
              <el-button
                type="info"
                plain
                icon="el-icon-sort"
                size="mini"
                @click="toggleExpandAll"
              >展开/折叠</el-button>
            </el-col>
          </div>

          <el-table
            v-if="refreshTable"
            v-loading="loading"
            :data="classList"
            row-key="classId"
            :default-expand-all="isExpandAll"
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          >
            <el-table-column label="类名称" align="left" prop="className" />
          </el-table>


        </el-card>
      </el-col>

      <el-col :span="8">
        <el-card class="box-card">
          <div class="container">
            <button @click="openpdf">打开pdf</button>
            <vueshowpdf @closepdf="closepdf"
                        v-model="isshowpdf"
                        :pdfurl="src"
                        @pdferr="pdferr"
                        :maxscale='4'
                        :minscale='0.6'
                        :scale='1.0'></vueshowpdf>
          </div>
        </el-card>
      </el-col>

      <el-col :span="8">
        <el-card class="box-card">
          <div>
            <!-- 按钮或链接，点击时触发弹窗 -->
            <button @click="openPdfDialog">打开PDF</button>

            <!-- 弹窗 -->
            <div v-if="showPdfDialog" class="pdf-dialog">
              <div class="pdf-content">
                <embed :src="pdfUrl" type="application/pdf" width="100%" height="500px">
              </div>
            </div>
          </div>
        </el-card>
      </el-col>

    </el-row>

  </div>
</template>

<script>

import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import vueshowpdf from "vueshowpdf";
export default {
  name: "Show",
  components: {
    Treeselect,
    vueshowpdf
  },
  data() {
    return {
      showPdfDialog: false,
      pdfUrl: '',
      pdfurls:'F:\\importEngine\\56#\\工程准备阶段文件（A类）\\0010.pdf.pdf',
      src: 'F:\\0010.pdf',
      isshowpdf: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 类别表格数据
      classList: [],
      // 类别树选项
      classOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部展开
      isExpandAll: false,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        parentId: null,
        className: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleColumnClick(row) {
      // 在这里处理点击事件，你可以通过'row'参数访问行数据
      console.log('点击了列：', row);
    },
    closepdf () {
      this.isshowpdf = false
    },
    pdferr (errurl) {
      console.log(errurl)
    },
    openpdf () {
      this.isshowpdf = true
    },


    /** 查询类别列表 */
    getList() {
      this.loading = true;
      listClass(this.queryParams).then(response => {
        this.classList = this.handleTree(response.data, "classId", "parentId");
        this.loading = false;
        console.log(this.classList)
      });
    },

    /** 转换类别数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.classId,
        label: node.className,
        children: node.children
      };
    },

    /** 查询类别下拉树结构 */
    getTreeselect() {
      listClass().then(response => {
        this.classOptions = [];
        const data = { classId: 0, className: '顶级节点', children: [] };
        data.children = this.handleTree(response.data, "classId", "parentId");
        this.classOptions.push(data);
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.form = {
        classId: null,
        parentId: null,
        className: null
      };
      this.resetForm("form");
    },

    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },

    openPdfDialog() {
      // 根据地址设置要显示的PDF文件路径
      this.pdfUrl = 'F:\\importEngine\\56#\\工程准备阶段文件（A类）\\0010.pdf.pdf';

      // 打开弹窗
      this.showPdfDialog = true;
    }

  }
};
</script>


<style>
.pdf-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  font-family: PingFang SC;
  width: 100%;
}
.pdf-content {
  width: 80%;
  max-width: 800px;
  background-color: #fff;
  padding: 20px;
}
</style>

